<template>
  <div class="app-container">
    <el-card class="box-card" shadow="never">
      <el-row :gutter="20">
        <el-col :span="2"><el-input size="mini" placeholder="楼宇名称"></el-input>
        </el-col>
        <el-col :span="2"><el-input size="mini" placeholder="楼宇名称"></el-input>
        </el-col>
        <el-col :span="2"><el-input size="mini" placeholder="楼宇名称"></el-input>
        </el-col>
        <el-col :span="6">
          <el-button type="primary" size="mini" @click="HandlerSeach()">查询</el-button></el-col>
      </el-row>
    </el-card>

    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row
      style="margin-top: 1%; font-size: 13px">
      <el-table-column label="所属企业" align="center">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="所属企业" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryName }}
        </template>
      </el-table-column>
      <el-table-column label="所属企业" align="center">
        <template slot-scope="scope">
          {{ scope.row.industry }}
        </template>
      </el-table-column>
      <el-table-column label="头像" align="center">
        <template slot-scope="scope">
          {{ scope.row.manufacturer }}
        </template>
      </el-table-column>

      <el-table-column label="头像" align="center">
        <template slot-scope="scope">
          {{ scope.row.manufacturerTel }}
        </template>
      </el-table-column>

      <el-table-column label="店铺名称" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryCategory }}
        </template>
      </el-table-column>

      <el-table-column label="店铺地址" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryNature }}
        </template>
      </el-table-column>

      <el-table-column label="联系人" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryAgency }}
        </template>
      </el-table-column>

      <el-table-column label="电话" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryKind }}
        </template>
      </el-table-column>

      <el-table-column label="营业开始时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessoryType }}
        </template>
      </el-table-column>

      <el-table-column label="文件" align="center">
        <template slot-scope="scope">
          {{ scope.row.vocUrl }}
        </template>
      </el-table-column>


      <el-table-column label="状态" align="center" width="150">
        <template slot-scope="scope">
          <el-tag type="primary" v-if="scope.row.review == 1" size="mini">待审核</el-tag>
          <el-tag type="success" v-if="scope.row.review == 2" size="mini">审核通过</el-tag>
          <el-tag type="danger" v-if="scope.row.review ==3" size="mini">审核不通过</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="创建时间" align="center" width="160">
        <template slot-scope="scope">
          {{ scope.row.creationTime | formatYmd }}
        </template>
      </el-table-column>

      <el-table-column align="center" prop="created_at" label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleDetails(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block" style="text-align: center">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="where.currentPage" :page-sizes="[10, 15, 20, 25, 30]" :page-size="where.pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import { getOrganicCompanyById } from "@/api/custom";

  export default {
    filters: {
      statusFilter(status) {
        const statusMap = {
          published: "success",
          draft: "gray",
          deleted: "danger",
        };
        return statusMap[status];
      },
    },
    data() {
      return {
        list: null,
        listLoading: true,
        where: {
          pageSize: 15,
          pageIndex: 1,
          // state: "",
          // reference: "",
          // negotiator: "",
          // customName: "",
          // customPhone: "",
          // isIncreaseWX: "",
          // isToStore: "",
        },
        total: 0,
        form: {
          id: null,
          avatar: "",
          intro: "",
          enterpriseId: 10,
          merchantName: "测试店铺22",
          merchantAddress: "成都市高新区科园南二路6号1栋1层1号",
          merchantLat: "",
          merchantLng: "",
          merchantUser: "测试",
          merchantPhone: "18628268873",
          businessHours: "09:00",
          businessEndHours: "22:00",
          merchantLabel: "生活",
          merchantPhoto: "",
          remarks: "",
        },
      };
    },
    created() {
      this.fetchData(this.where);
    },
    methods: {
      fetchData(obj) {
        this.listLoading = true;
        getOrganicCompanyById(obj)
          .then((response) => {
            console.log(response);
            this.listLoading = false;
            this.list = response.data.list;
            this.total = response.data.total;
          })
          .catch((error) => {
            console.log(error);
          })
          .finally(() => {
            this.listLoading = false;
          });
      },
      handleSizeChange(val) {
        this.where.pageSize = val;
        this.fetchData(this.where);
      },
      handleCurrentChange(val) {
        console.log(val);
        this.where.currentPage = val;
        this.fetchData(this.where);
      },
      HandlerSeach() {
        this.fetchData(this.where);
      },
      handleDetails(id) {
        console.log("Details" + id);
        getMerchantStoreById(id).then((response) => {
          console.log(response);
        });
      },
    },
  };
</script>